package com.qire.manhua.dal.service;

import com.qire.antsbinder.dal.DataService;
import com.qire.antsbinder.dal.annotation.StrategyAnnotation;
import com.qire.common.constant.CustomEvent;
import com.qire.common.constant.Url;
import com.qire.common.dal.WarehouseFactory;
import com.qire.common.model.entity.UserEntity;
import com.qire.common.utils.NoticeEventBus;
import com.qire.common.utils.ToastHelper;
import com.qire.common.widget.snackbar.Prompt;
import com.qire.manhua.dal.ICommentDataDAL;
import com.qire.manhua.dal.IUserDataDAL;
import com.qire.manhua.model.vo.OkResponseVO;

/**
 * 漫画评论数据服务
 */
public class ComicCommentService extends DataService {

    private final ICommentDataDAL commentDataDAL = WarehouseFactory.create(this, ICommentDataDAL.class);
    private final IUserDataDAL userDataDAL = WarehouseFactory.create(this, IUserDataDAL.class);

    public ComicCommentService() {
    }

    /**
     * 提交评论
     * @param bookId 书籍ID
     * @param chapterId 章节ID
     * @param content 评论内容
     */
    public void submitComment(int bookId, int chapterId, String content) {
        commentDataDAL.submitComment(bookId, chapterId, 0, content, 5);
    }
    @StrategyAnnotation(event = Url.comment_add)
    public void submitCommentApiCallback(OkResponseVO dataVO, boolean isCache) {
        NoticeEventBus.NOTICE.sendEvent(CustomEvent.COMMENT_SUBMIT_SUCCESS);
    }

    /**
     * 更新昵称到服务器
     */
    public void updateNickname() {
        userDataDAL.updateNickname(UserEntity.self.getName());
    }
    @StrategyAnnotation(event = Url.v5_nicknameUpdate)
    public void nicknameUpdateApiCallbackRefresh(OkResponseVO okResponseVO, boolean isCache) {
        //修改昵称API调用后回调处理
        if(okResponseVO.isOK()) {
            ToastHelper.showSnackBar("昵称修改成功！", Prompt.SUCCESS);
            NoticeEventBus.NOTICE.sendEvent(CustomEvent.USER_UPDATE_REFRESH);
        } else {
            ToastHelper.showSnackBar("昵称修改失败！", Prompt.ERROR);
        }
    }

}
